package tools.blast;

import java.io.BufferedReader;
import java.io.IOException;

public class blastM8Parser {
	BufferedReader in;
	private boolean hasMore=true;
	private blastM8Alignment hit=null;
	
	public blastM8Parser(BufferedReader in) throws IOException,Exception{
		this.in=in;
		readNext();
	}
	
	public boolean hasMore(){
		return hasMore;
	}
	
	public blastM8Alignment nextHit()throws Exception{
		if(!hasMore)
			throw new Exception("No more hits");
		blastM8Alignment tmp=hit;
		readNext();
		return tmp;
	}
	
	private void readNext() throws IOException,Exception{
		String s=in.readLine();
		if(s==null){
			hasMore=false;
		} else{
			blastM8Alignment align=new blastM8Alignment(s);
			hit=new blastM8Alignment(align);
			hasMore=true;
		}
	}
}
